import numpy as npimport matplotlib.pyplot as pltimport matplotlib%config InlineBackend.figure_format='retina'# to change default colormapplt.rcParams["image.cmap"] ="Set3"# to change default color cyclemyC= plt.cm.tab20b.colorsplt.rcParams['axes.prop_cycle'] = plt.cycler(color=myC[:1]+myC[2:])matplotlib.rcParams['figure.figsize'] = (20, 10)plt.style.use('seaborn-v0_8-whitegrid')m1 = np.array([[1,2], [3,4], [1,1], [5,4]])#two dimenstional tensorweight = np.array([0.5,0.5])#what tensor will try to guessnp.dot(m1,weight)#if this were a scala problem this the value will be used for relu activation
array([1.5, 3.5, 1. , 4.5])
What maybe powerful is matrix will changes shapes. Would it matter what input shape I choose?
Code
print('weight2 is')weight2 = np.array([[0.5,0.1,0.3], [0.5,0.2,0.3]])#you can expand infinitly horisentallyprint(weight2)print('Using dot product we expand the width of the matrix to 3')print(np.dot(m1,weight2))print('Use another product to trave the dimension back ')weight3 = np.array([[0.1,0.2], [0.9,0.1], [0.2,0.5]])m3 = np.dot(np.dot(m1,weight2),weight3)print(m3)print("notice how the first matrix expand matrix dimention to 3 and the second to 2;")
weight2 is
[[0.5 0.1 0.3]
[0.5 0.2 0.3]]
Using dot product we expand the width of the matrix to 3
[[1.5 0.5 0.9]
[3.5 1.1 2.1]
[1. 0.3 0.6]
[4.5 1.3 2.7]]
Use another product to trave the dimension back
[[0.78 0.8 ]
[1.76 1.86]
[0.49 0.53]
[2.16 2.38]]
notice how the first matrix expand matrix dimention to 3 and the second to 2;
# This perhaps is really usefull to test to see what you neuro network is doing:rotator = np.array([ [0,1], [1,0]])figure,ax=plt.subplots(figsize=(5,5))m1=np.random.random((50,2))m2=my_transformation(m1, rotator)plot_transformation(m1,m2,ax=ax)
Explore Effect of Different Matrix on Univarity Sampled Matrix: